package com.beta.cms.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beta.cms.common.annotation.DataAnnotation;
import com.beta.cms.dao.UserDao;
import com.beta.cms.model.entity.User;
import com.beta.cms.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private UserDao userDao;

	@Override
	@Transactional
	public int save(User user) {
		userDao.save(user);
		// System.out.println(1 / 0);
		return 1;
	}

	@Override
	@DataAnnotation
	public User queryAnnotation() {
		logger.info("我是第1次劝不住");
		return null;
	}

	@Override
	@Cacheable(value = "cache1m", key = "'queryEhcache'+#name")
	public User queryEhcache(String name) {
		User user = new User();
		user.setId(1l);
		user.setName(name);
		logger.info("你的名字 " + name);
		return user;
	}

	@Override
	// @DataSourceChange(slave = true)
	public User queryById(Long id) {
		// TODO Auto-generated method stub
		return userDao.loadById(id);
	}

}
